package cn.rui.controller;

import cn.rui.aop.Log;
import cn.rui.pojo.Image;
import cn.rui.service.ImgService;
import cn.rui.vo.ImageQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/**
 * 文件上传功能
 *
 * @author 徽州大都督
 * @date 2020/8/16
 */
@RestController
@RequestMapping("img")
public class ImgConroller {

    @Autowired
    private ImgService imgService;

    /**
     * 图片上传
     *
     * @param file
     * @return
     */
    //MultipartFile file
    @PostMapping("upload")
    @Log("上传了图片")
    public String uploadImg(MultipartFile file, String statusStr, String category, String descImg) throws IOException {
        return imgService.uploadImg (file, statusStr, category, descImg);

    }

    /**
     * 分页查询
     *
     * @param page
     * @param size
     * @return
     */
    @PostMapping("findByPage/{page}/{size}")
    public List<Image> findByPage(@PathVariable("page") int page, @PathVariable("size") int size, @RequestBody ImageQuery query) {


        return imgService.findByPage (page, size, query);
    }

    /**
     * 删除图片
     *
     * @param mid
     */
    @Log("删除广告图片")
    @DeleteMapping("delImg/{mid}")
    public void delImg(@PathVariable("mid") Integer mid) {
        imgService.delImg (mid);
    }

    /**
     * 更新图片显示/隐藏
     *
     * @param mid
     */
    @Log("更新了图片状态")
    @PutMapping("updateStatus/{mid}")
    public void updateStatus(@PathVariable("mid") Integer mid) {
        imgService.updateStatus (mid);
    }
}
